//
//  FirstDetailDetailViewController.m
//  Protect -A
//
//  Created by 付剑英 on 16/6/22.
//  Copyright © 2016年 付剑英. All rights reserved.
//

#import "FirstDetailDetailViewController.h"
#import "BaseButton.h"

#import <ShareSDK/ShareSDK.h>
#import <ShareSDKUI/ShareSDK+SSUI.h>
@interface FirstDetailDetailViewController ()<UIWebViewDelegate>
@property (nonatomic,retain)UIWebView *wv;
@property (nonatomic,retain)BaseButton  *Dianji;
@property (nonatomic,retain)NSString *url1;
@end

@implementation FirstDetailDetailViewController

-(void)dealloc{

    [_DetailID release];
    [_wv release];
    [_Dianji release];
    [_url1 release];
    [super dealloc];

}

- (void)viewDidLoad {
    
    [super viewDidLoad];
    [self createWebView];
    self.navigationItem.title =@"礼遇详情";
    // Do any additional setup after loading the view.

}
#pragma mark - ------------ 创建WebView ---------------

-(void)createWebView{
  
    //创建
    self.wv = [[UIWebView alloc]initWithFrame:CGRectMake(0, -50, self.view.frame.size.width, self.view.frame.size.height + 50)];
    self.wv.delegate = self;
    //页面缩放
    self.wv.scalesPageToFit = YES;
    //用户交互
    self.wv.userInteractionEnabled = YES;
    //加载页面
    NSString *html = [NSString stringWithFormat:@"https://enjoy.ricebook.com/product/%@",_DetailID];
    NSURL *url= [NSURL URLWithString:html];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    [self.wv loadRequest:request];
    [self.view addSubview:self.wv];
   
    UIBarButtonItem *ri = [[UIBarButtonItem alloc]initWithTitle:@"分享" style:UIBarButtonItemStylePlain target:self action:@selector(handle:)];
    self.navigationItem.rightBarButtonItem = ri;
    
}

-(void)handle:(UIBarButtonItem *)button{
    
    NSArray* imageArray = [UIImage imageNamed:@"A6.jpg"];
  
    //（注意：图片必须要在Xcode左边目录里面，名称必须要传正确，如果要分享网络图片，可以这样传iamge参数 images:@[@"http://mob.com/Assets/images/logo.png?v=20150320"]）
    if (imageArray) {
        
        NSMutableDictionary *shareParams = [NSMutableDictionary dictionary];
        [shareParams SSDKSetupShareParamsByText:@"分享内容"
                                         images:imageArray
                                            url:[NSURL URLWithString:@"http://mob.com"]
                                          title:@"分享标题"
                                           type:SSDKContentTypeAuto];
        //2、分享（可以弹出我们的分享菜单和编辑界面）
        [ShareSDK showShareActionSheet:nil //要显示菜单的视图, iPad版中此参数作为弹出菜单的参照视图，只有传这个才可以弹出我们的分享菜单，可以传分享的按钮对象或者自己创建小的view 对象，iPhone可以传nil不会影响
                                 items:nil
                           shareParams:shareParams
                   onShareStateChanged:^(SSDKResponseState state, SSDKPlatformType platformType, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error, BOOL end) {
                       
                       switch (state) {
                           case SSDKResponseStateSuccess:
                           {
                               UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"分享成功"
                                                                                   message:nil
                                                                                  delegate:nil
                                                                         cancelButtonTitle:@"确定"
                                                                         otherButtonTitles:nil];
                               [alertView show];
                               break;
                           }
                           case SSDKResponseStateFail:
                           {
                               UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"分享失败"
                                                                               message:[NSString stringWithFormat:@"%@",error]
                                                                              delegate:nil
                                                                     cancelButtonTitle:@"OK"
                                                                     otherButtonTitles:nil, nil];
                               [alert show];
                               break;
                           }
                           default:
                               break;
                       }
                   }
         ];}
   }




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
